package br.com.merks.controller;

import br.com.caelum.vraptor.validator.Validations;
import br.com.merks.model.Market;
import br.com.merks.model.MarketAnswer;
import br.com.merks.model.User;

public class ValidationRules {
	/**
	 * UsersController
	 */
	public static Validations isValidUserRegistrationInput( final User iut) {
		return new Validations() {{
		     that( ! (iut == null), "user.name", "nome.vazio");
		     that( ! (iut.getEmail()== null), "user.email", "email.vazio");
		     that( ! (iut.getLogin() == null), "user.login", "login.vazio");
		     that( ! (iut.getPassword() == null), "user.password", "password.vazio");
		     that( ! ( (iut.getPassword() != null) && (iut.getPassword().length() < 6)), "user.password", "password.pequeno");
		     that( ! ( !iut.getPassword().equals(iut.getPassword2())), "user.password", "password.invalido");
		}};
	}
	public static Validations isValidUserEditionInput ( final User iut ) {
		return new Validations() {{
		     that( ! (iut == null), "user.name", "nome.vazio");
		     that( ! (iut.getEmail()== null), "user.email", "email.vazio");
		     that( ! ( (iut.isPasswordEdited()) && (iut.getPassword() != null) && (iut.getPassword().length() < 6)), "user.password", "password.pequeno");
		     that( ! ( (iut.isPasswordEdited()) && !iut.getPassword().equals(iut.getPassword2())), "user.password", "password.invalido");
		}};
	}
	/**
	 * QuestionsController 
	 */
	public static Validations isValidQuestionRegistrationInput ( final Market iut ) {
		return new Validations() {{
		     that( ! (iut == null), "form", "formulario.vazio");
		     that( ! (iut.getTitle()== null), "market.title", "title.vazio");
		     that( ! (iut.getDescription()== null), "market.description", "description.vazio");
		}};
	}
	public static Validations isValidQuestionAnwsersRegistrationInput ( final MarketAnswer iut ) {
		return new Validations() {{
		     that( ! (iut == null), "form", "formulario.vazio");
		     that( ! (iut.getAnswer()== null), "marketAnswer.answer", "answer.vazio");
		     that( ! (iut.getStartValue()== null), "marketAnswer.startValue", "startValue.vazio");
		}};
	}
}
